package starter;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import quelle.DataSource;
import senke.DataSink;
import station.Station;

public class StartMany {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int tnmbr = 0;
		int mcastport = 0;
		int sendport = 0;
		int sinkport = 0;
		int recport = 0;
		int count = 0;
		String s = "";
		if(args.length == 5 || args.length == 6){
			tnmbr = Integer.parseInt(args[1]);
			mcastport = 15013;//+tnmbr;
			sinkport = Integer.parseInt(args[2]);
			sendport = Integer.parseInt(args[3]);
			recport = Integer.parseInt(args[4]);
			s = args[0];
			if(args.length == 6){
				count = Integer.parseInt(args[5]);
			}else{
				count = 1;
			}
		}else{
			tnmbr = 13;
			mcastport = 15013;//+tnmbr;
			sendport = 7777;
			recport = 7778;
			sinkport = 7779;
			count = 1;
			s = "225.10.1.12";
		}
		ExecutorService exec = Executors.newFixedThreadPool(3*count);
		for(int i = 0; i < count; i++){
			exec.execute(new Station(s,mcastport,recport,sinkport));
			exec.execute(new DataSink(sinkport));
			exec.execute(new DataSource(sendport,recport,tnmbr,null));
			sinkport+=3;
			sendport+=3;
			recport+=3;
			tnmbr++;
		}
		exec.shutdown();
	}

}
